package com.xintonghua.bussiness.ui.fragment.cube;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xintonghua.base.widget.ShowAllGridView;
import com.xintonghua.bussiness.BuildConfig;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.adapter.ConsumptionAdapter;
import com.xintonghua.bussiness.base.BaseFragment;
import com.xintonghua.bussiness.bean.DataCubeKeFuBean;
import com.xintonghua.bussiness.util.JsonUtil;
import com.xintonghua.bussiness.util.JumpUtils;
import com.xintonghua.bussiness.util.MyState;
import com.xintonghua.bussiness.util.MyUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 客户
 * 作者：wanxianyi
 * 时间：2018/1/11.
 * 包名：com.xintonghua.bussiness.ui.fragment.cube
 */
public class ClientServerFragment extends BaseFragment {


    @BindView(R.id.tv_lable_1)
    TextView tvLable1;
    @BindView(R.id.tv_all_client)
    TextView tvAllClient;
    @BindView(R.id.tv_lable_2)
    TextView tvLable2;
    @BindView(R.id.tv_all_atock)
    TextView tvAllAtock;
    @BindView(R.id.tv_lable_3)
    TextView tvLable3;
    @BindView(R.id.tv_zongkucun)
    TextView tvZongkucun;
    @BindView(R.id.tv_qudao)
    TextView tvQudao;
    @BindView(R.id.tv_kehu_xiaofei_money)
    TextView tvKehuXiaofeiMoney;
    @BindView(R.id.iv_normal)
    ImageView ivNormal;
    @BindView(R.id.tv_normal)
    TextView tvNormal;
    @BindView(R.id.tv_number)
    TextView tvNumber;
    @BindView(R.id.tv_jieshaomoney)
    TextView tvJieshaomoney;
    @BindView(R.id.rl_normal)
    RelativeLayout rlNormal;
    @BindView(R.id.iv_no)
    ImageView ivNo;
    @BindView(R.id.tv_no)
    TextView tvNo;
    @BindView(R.id.tv_tuiguang_money)
    TextView tvTuiguangMoney;
    @BindView(R.id.rl_no)
    RelativeLayout rlNo;
    @BindView(R.id.iv_belate)
    ImageView ivBelate;
    @BindView(R.id.tv_belate)
    TextView tvBelate;
    @BindView(R.id.rl_belate)
    RelativeLayout rlBelate;
    @BindView(R.id.tv_lao_kehu_xiaofei)
    TextView tvLaoKehuXiaofei;
    @BindView(R.id.iv_friend)
    ImageView ivFriend;
    @BindView(R.id.tv_friend)
    TextView tvFriend;
    @BindView(R.id.tv_pengyoujieshao)
    TextView tvPengyoujieshao;
    @BindView(R.id.iv_network)
    ImageView ivNetwork;
    @BindView(R.id.tv_network)
    TextView tvNetwork;
    @BindView(R.id.tv_l_tuiguang)
    TextView tvLTuiguang;
    @BindView(R.id.rl_network)
    RelativeLayout rlNetwork;
    @BindView(R.id.iv_other)
    ImageView ivOther;
    @BindView(R.id.tv_other)
    TextView tvOther;
    @BindView(R.id.tv_qita_qudao_money)
    TextView tvQitaQudaoMoney;
    @BindView(R.id.rl_other)
    RelativeLayout rlOther;
    Unbinder unbinder;
    @BindView(R.id.gv_new_customer)
    ShowAllGridView gvNewCustomer;
    @BindView(R.id.gv_old_customer)
    ShowAllGridView gvOldCustomer;

    @Override
    public int getLayout() {
        return R.layout.fragment_server_client;
    }

    @Override
    public void initUI(View view) {
        unbinder = ButterKnife.bind(this, view);
        getNetData();
    }

    public void getNetData() {
        httpCent.showCustomer(getArguments().getInt(BuildConfig.FLAVOR),"", "", this, MyState.requestOne);
    }

    @OnClick({R.id.tv_time_saixuan})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_time_saixuan:
                Bundle bundle = new Bundle();
                bundle.putInt(BuildConfig.FLAVOR, getArguments().getInt(BuildConfig.FLAVOR));
                MyUtils.openActivity(getActivity(), CustomerSaiXuanActivity.class, bundle);
               // JumpUtils.jumpto(getActivity(), CustomerSaiXuanActivity.class, null);
                break;
        }
    }

    @Override
    public void dataBack(Object data, int order) {
        super.dataBack(data, order);
        try {
            switch (order) {
                case MyState.requestOne:
                    bean = JsonUtil.getEntityByJsonString(data.toString(), DataCubeKeFuBean.class);
                    initData();
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    DataCubeKeFuBean bean;

    public void initData() {
        tvAllClient.setText("" + bean.getTotalCount());//到店总客户数
        tvAllAtock.setText("" + bean.getNewCount());//
        tvZongkucun.setText("" + bean.getOldCount());
        tvKehuXiaofeiMoney.setText("" + bean.getNewCusMoney() + "元");
        tvJieshaomoney.setText("" + bean.getNewCusByCus() + "元");
        tvTuiguangMoney.setText("" + bean.getNewCusByShopUser() + "元");
        tvLaoKehuXiaofei.setText("" + bean.getOldCusMoney() + "元");
        tvPengyoujieshao.setText("" + bean.getOldCusByCus() + "元");
        tvLTuiguang.setText("" + bean.getOldCusByshopUser() + "元");
        gvNewCustomer.setAdapter(new ConsumptionAdapter(bean.getNewResource(), getActivity()));
        gvOldCustomer.setAdapter(new ConsumptionAdapter(bean.getOldResource(), getActivity()));

    }


}
